<template>
	<view :class="[config.style]">
		<view class="bond-section">
			<view class="from">
				<view class="realname">
					<input class="uni-input" focus :placeholder="placeholder" v-model="realname" />
				</view>
			</view>
			<view class="submit">
				<button type="default" class="button" hover-class="button-hover" @click="submitBind()">确 认</button>
			</view>
		</view>
	</view>
</template>

<script>
	import { mapState,mapMutations } from 'vuex'
	
	export default {
		data() {
			return {
				urlParams: {},
				placeholder: '请输入真实姓名',
				realname: '',
				userInfo: {},
			}
		},
		onLoad(option) {
			//获取url参数
			console.log(option)
			this.urlParams = option
		},
		created() {
			this.getUserInfo()
		},
		computed: {
			...mapState(['config'])
		},
		methods: {
			/**
			 * 获取用户详情数据
			 */
			getUserInfo: function(){
				let that = this
				let data = {}
					data.action = 'user_info'
					data.m = 'muu_classroom'
				//动态获取用户数据
				let url = ''
					//#ifdef MP-WEIXIN
					url = 'entry/wxapp/ucenter'
					//#endif
					//#ifdef H5
					url = 'entry/site/ucenter'
					//#endif
				this.util.request({
					url : url,
					data : data,
					success: function (res) {
						if (res.data.code == 200) {
							//console.log(res.data)
							that.userInfo = res.data.data
						}
					}
				})
			},
			
			/**
			 * 提交
			 */
			submitBind: function(){
				let that = this
				let receiver = this.realname
				let data = {}
				data.action = 'realname'
				data.realname = receiver
				//获取全局配置
				let url = ''
					//#ifdef MP-WEIXIN
					url = 'entry/wxapp/ucenter'
					//#endif
					//#ifdef H5
					url = 'entry/site/ucenter'
					//#endif
				this.util.request({
					url : url,
					data: data,
					method: 'POST',
					success: function (res) {
						//console.log(res.data);
						uni.showToast({
							title: res.data.msg,
							duration: 2000,
							icon: 'none'
						});
						// 成功后返回上一页
						if(res.data.code == 200){
							uni.navigateBack()
						}
					},
					fail: function(){
						uni.showToast({
							title: '发生错误',
							duration: 2000,
							icon: 'none'
						});
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		background-color: #f8f8f8;
		min-height: 100%;
		height: auto;
	}
	.bond-section {
		padding: 20rpx;
		border-radius: 10rpx;
		.title {
			text-align: center;
			font-size: 32rpx;
			line-height: 48rpx;
			font-weight: 700;
		}
		.from {
			margin-top: 40rpx;
			margin-bottom: 40rpx;
			.realname {
				background-color: #fff;
				border-bottom: 2rpx solid #f8f8f8;
				padding: 10rpx 20rpx;
				input {
					height: 92rpx;
					line-height: 92rpx;
				}
			}
		}
		.submit {
			button {
				color: #fff;
			}
		}
	}
	
	/*页面风格设计*/
	.Blue {
		.button {
			background-color: $Blue;
		}
		.button-hover {
			background-color: $Blue-hover;
		}
	}
	.Green {
		.button {
			background-color: $Green;
		}
		.button-hover {
			background-color: $Green-hover;
		}
	}
	.LightRed {
		.button {
			background-color: $LightRed;
		}
		.button-hover {
			background-color: $LightRed-hover;
		}
	}
	.Orange {
		.button {
			background-color: $Orange;
		}
		.button-hover {
			background-color: $Orange-hover;
		}
	}
	.LightPink {
		.button {
			background-color: $LightPink;
		}
		.button-hover {
			background-color: $LightPink-hover;
		}
	}
	.Magenta {
		.button {
			background-color: $Magenta;
		}
		.button-hover {
			background-color: $Magenta-hover;
		}
	}
</style>
